<?php 
/**
 * 数组第一维信息：每一周开始 结束 以及week数组（第二维）
 * 第二维告诉我们今天的日期 星期 以及 24个小时的情况
 */ 
?>
<?php if($dateTable === null):?>
    <blockquote class="meta">
    <h4 class="text-error"><i>No records found.</i></h4>
    <?php return;?>
<?php endif;?>

<style type="text/css">
.datetimetable td
{
    text-align:center;
}
.datetimetable th
{
    text-align:center;
}
.datetimetable a
{
    cursor:pointer;
}
</style>
<?php
//向昨天找到最近的星期天
$backDay = date('w',time());
$sunday = strtotime("- {$backDay} days", time());
$flag = null;
$boolean = false;
for($i = 0; $i < count($dateTable); $i++)
{
    if($dateTable[$i]['start_date'] == date('Y-m-d', $sunday))
    {
        $flag = $dateTable[$i]['start_date'];
        $boolean = true;
    }
}
if($flag == null)
{
    $flag = $dateTable[0]['start_date'];
}
?>
<div id="statisticstable">
<p>
<b>注意：</b><font color="red"><?php echo $model->title?></font>
的预约时间单位为<font color="blue">60分钟</font>
, 收费标准为<font color="blue"><?php echo $model->price?>元/小时</font>
, 最多提前预约 <font color="blue">2</font>
周, 最少提前 <font color="blue">120</font> 分钟预约 
</p>
<p>
    <img src="<?php echo yii::app()->baseUrl?>/images/ico-validbook.png"> 可预约 </img>
    <span style="margin-right:20px"></span>
    <img src="<?php echo yii::app()->baseUrl?>/images/ico-invalidbook.png"> 不可预约 </img>
    <span style="margin-right:20px"></span>
    <img src="<?php echo yii::app()->baseUrl?>/images/ico-minebook.png"> 已预约 </img>
    <span style="margin-right:20px"></span>
    <img src="<?php echo yii::app()->baseUrl?>/images/ico-booking.png"> 已选择 </img>
</p>
<span id="start" value="<?php echo 'tableinfo_'.$flag?>"></span>
<?php for($i = 0; $i < count($dateTable); $i++):?>
<div id="tableinfo_<?php echo $dateTable[$i]['start_date']?>" class="datetable">
<table class="table table-bordered table-stripped datetimetable">
    <caption>
        <h4>
        <nav class="nav">
            <span style="margin-right:30px"><?php echo $dateTable[$i]['start_date'].'~'.$dateTable[$i]['end_date']?></span>
            <?php if($i == 0):?>
            <span>&lt;&lt;上一周</span>
            <?php else:?>
            <a class="changeweek" value="<?php echo 'tableinfo_'.$dateTable[$i-1]['start_date']?>">&lt;&lt;上一周</a>
            <?php endif;?>

            <?php if($dateTable[$i]['start_date'] == $flag):?>
            <span>本周</span>
            <?php elseif($boolean):?>
            <a class="changeweek" value="<?php echo 'tableinfo_'.$flag?>">本周</a>
            <?php else:?>
            <span>本周</span>
            <?php endif;?>

            <?php if($i == count($dateTable)-1):?>
            <span>下一周&gt;&gt;</span>
            <?php else:?>
            <a class="changeweek" value="<?php echo 'tableinfo_'.$dateTable[$i+1]['start_date']?>">下一周&gt;&gt;</a>
            <?php endif;?>
        </nav>
        </h4>
    </caption>
    <thead>
        <th style="padding-bottom:15px">预约时间段</th>
        <?php for($j = 0; $j < 7; $j++):?>
        <th>
            <?php echo date('m.d', strtotime($dateTable[$i][$j]['date'])).'<br/>'?>
            <font color="<?php if($dateTable[$i][$j]['day'] == '星期天' || $dateTable[$i][$j]['day'] == '星期六'){ echo "#F00";}?>">
            <?php echo $dateTable[$i][$j]['day']?>
            </font>
        </th>
        <?php endfor;?>
    </thead>
    <tbody>
        <?php $start = '2014-12-12 00:00:00';?>
        <?php for($j = 0; $j < 24; $j++):?>
        <tr>
            <td>
            <?php echo date('H:i', strtotime($start));?>-
            <?php $start = date('Y:m:d H:i:s', strtotime('+ 1 hours', strtotime($start)));?>
            <?php echo date('H:i', strtotime($start));?>
            </td>
            <?php for($k = 0; $k < 7; $k++):?>
            <td>
                <?php if($dateTable[$i][$k][$j] == -1):?>
                    <img src="<?php echo yii::app()->baseUrl?>/images/ico-invalidbook.png"/>
                <?php elseif($dateTable[$i][$k][$j] == -2):?>
                    <img src="<?php echo yii::app()->baseUrl?>/images/ico-minebook.png"/>
                    已预约
                <?php elseif($dateTable[$i][$k][$j] == $model->stock):?>
                    <img src="<?php echo yii::app()->baseUrl?>/images/ico-invalidbook.png"/>
                    <?php echo $dateTable[$i][$k][$j].'/'.$model->stock?>
                    满人
                <?php else:?>
                    <img class="img_class" value="<?php echo $i.$k.$j?>" url="<?php echo yii::app()->baseUrl?>" src="<?php echo yii::app()->baseUrl?>/images/ico-validbook.png"/>
                    <?php echo $dateTable[$i][$k][$j].'/'.$model->stock?>
                    <?php $his = date('H:i:s', strtotime('- 1 hours', strtotime($start)));?>
                    <input type="text" id="input_id_<?php echo $i.$k.$j?>"
                         name="checkbox[<?php echo date('Y-m-d', strtotime($dateTable[$i][$k]['date'])).' '.$his?>]" style="display:none"></input>
                <?php endif;?>
            </td>
            <?php endfor;?>
        </tr>
        <?php endfor;?>
    </tbody>
</table>
</div>
<?php endfor;?>
</div>
